<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>开始使用 layui</title>
    <!-- 引入layui的样式表 -->
    <link rel="stylesheet" href="./layui/css/layui.css">
</head>
<body style="padding-top:100px" class="layui-bg-black">

<!-- 你的 HTML 代码 start -->
    <div class="layui-container" >
        <div class="layui-row">
            <!-- 偏移4列 -->
            <div class="layui-col-md4 layui-col-md-offset4">

                <div class="layui-card layui-bg-gray">
                    <div class="layui-card-header">请登录</div>
                    <div class="layui-card-body">
                        <form class="layui-form">

                            <!-- 用户名输入框 -->
                            <div class="layui-form-item">
                                <label class="layui-form-label"><i class="layui-icon layui-icon-username"></i></label>
                                <div class="layui-input-inline">
                                    <!-- lay-verify="required" 拓展属性 和校验相关 -->
                                    <input type="text" name="username" required  lay-verify="required" placeholder="请输入用户名" autocomplete="off" class="layui-input">
                                </div>
                            </div>

                            <!-- 密码输入框 -->
                            <div class="layui-form-item">
                                <label class="layui-form-label"><i class="layui-icon layui-icon-key"></i></label>
                                <div class="layui-input-inline">
                                    <input type="password" name="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
                                </div>
                            </div>


                            <!-- 验证码输入框 -->
                            <div class="layui-form-item">
                                <label class="layui-form-label"><i class="layui-icon layui-icon-vercode"></i></label>
                                <div class="layui-input-inline">
                                    <input type="text" name="captchar" required lay-verify="required" placeholder="请输入验证码" autocomplete="off" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label"><i class="layui-icon layui-icon-vercode"></i></label>
                                <div class="layui-input-inline">
                                    <img id="captcharimg" src="/capchar">
                                </div>
                            </div>

                            <!-- 提交、重置按钮 -->
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" lay-submit lay-filter="loginForm">立即提交</button>
                                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 你的 HTML 代码 end -->

<!-- 引入js文件 -->
<script src="./layui/layui.js"></script>
<script>
    /* layui弹出层layer 表单组件form 可省略 */
    //layui.use(['layer', 'form'], function(){
    layui.use(function(){

        //选择要使用的组件 弹出层和表单
        var layer = layui.layer
            ,form = layui.form;

        //引入jquery的核心对象 不用百度CDN了
        var $ = layui.$;



        //监听提交
        form.on('submit(loginForm)',function (data){

            console.log(data.field);  //把表单中填好的数据 对应的 js对象 打印出来

            //回调函数
            //layer.msg(JSON.stringify(data.field));

            //发送ajax请求给后端登录接口
            $.ajax({
                url:'',
                type:'get',
                success:function(ret) {
                    console.log(ret);
                }
            });

            //取消表单的默认提交行为
            return false;
        });
    });
</script>

</body>
</html>